<template>
  <div style="width: 80%">
    <div style="margin-bottom: 30px">编辑图书分类</div>
    <el-form  :model="form" style="width: 800px" :rules="rules" ref="ruleForm" label-width="100px">
      <el-form-item label="名字" prop="name">
        <el-input v-model="form.name" placeholder="请输入名字"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" placeholder="备注"></el-input>
      </el-form-item>
      <div style="text-align: center; margin-top: 30px">
        <el-button type="primary" @click="update" size="medium">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";

export default {
  name: "EditCategory",
  data(){
    return{
      rules:{
        name: [
          { required: true, message: '请输入名字', trigger: 'blur'}
        ],
      },
      form:{

      }
    }
  },
  created() {
    var id = this.$route.query.id;
    request.get("/category/"+id).then(res=>{
      if(res.code=='200'){
        this.form=res.data
      }
    })
  },
  methods:{
    update(){
      this.$refs['ruleForm'].validate((valid) => {
        if(valid){
          request.put("/category/",this.form).then(res=>{
            if(res.code=='200'){
              this.$notify.success("修改成功");
              this.$router.push('/categoryList')
            }else{
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>